<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class General{

	function convertDateFromDmyToYmd($date){
		if(!$this->is_date($date)) return NULL;
		list($day, $month, $year) = explode('/', $date);
		$dbDate = $year.'/'.$month.'/'.$day;
		return date('Y-m-d', strtotime($dbDate));
	}

	function convertDateFromDmyToTime($date){
		if(!$this->is_date($date)) return NULL;
		list($day, $month, $year) = explode('/', $date);
		$dbDate = $year.'/'.$month.'/'.$day;
		return strtotime($dbDate);
	}

	function is_date( $str )
	{
		$stamp = strtotime( $str );

		if (!is_numeric($stamp))
		{
			return FALSE;
		}
		$month = date( 'm', $stamp );
		$day   = date( 'd', $stamp );
		$year  = date( 'Y', $stamp );

		if (checkdate($month, $day, $year))
		{
			return TRUE;
		}

		return FALSE;
	}
}